package edu.cuit.zhuyimeng.aircraft.controller;

import edu.cuit.zhuyimeng.aircraft.controller.dto.CreateAircraftDTO;
import edu.cuit.zhuyimeng.aircraft.service.IAircraftService;
import edu.cuit.zhuyimeng.framework.common.result.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员控制器
 */
@RestController
@RequestMapping("/admin")
@Tag(name = "管理员控制器", description = "管理员控制器")
@Validated
@RequiredArgsConstructor
public class AdminController {

    private final IAircraftService aircraftService;

    /**
     * 添加飞机
     */
    @PutMapping("/aircraft")
    @Operation(summary = "添加飞机",security = @SecurityRequirement(name = "Authorization"))
    public CommonResult<Void> addAircraft(@RequestBody @Valid CreateAircraftDTO createAircraftDTO) {
        aircraftService.addAircraft(createAircraftDTO);
        return CommonResult.success();
    }

    /**
     * 删除飞机
     */
    @DeleteMapping("/aircraft")
    @Operation(summary = "删除飞机",security = @SecurityRequirement(name = "Authorization"))
    public CommonResult<Void> deleteAircraft(@RequestParam("id") @NotNull Long id) {
        aircraftService.deleteAircraft(id);
        return CommonResult.success();
    }

    /**
     * 锁定飞机
     */
    @PostMapping("/aircraft/lock")
    @Operation(summary = "锁定飞机",security = @SecurityRequirement(name = "Authorization"))
    public CommonResult<Void> lockAircraft(@RequestParam("id") @NotNull Long id) {
        aircraftService.lockAircraft(id);
        return CommonResult.success();
    }

    /**
     * 解锁飞机
     */
    @PostMapping("/aircraft/unlock")
    @Operation(summary = "解锁飞机",security = @SecurityRequirement(name = "Authorization"))
    public CommonResult<Void> unlockAircraft(@RequestParam("id") @NotNull Long id) {
        aircraftService.unlockAircraft(id);
        return CommonResult.success();
    }

}
